from django.db import models

# Create your models here.
# 会员模型
class Users(models.Model):
    # 用户名 密码 手机号 邮箱 性别 年龄 头像 注册时间 状态
    username = models.CharField(max_length=50)
    password = models.CharField(max_length=77)
    phone = models.CharField(max_length=11)
    email = models.CharField(max_length=100,null=True)
    sex = models.CharField(max_length=1,choices=((1,'男'),(0,'女')),null=True)
    age = models.IntegerField(null=True)
    pic_url = models.CharField(max_length=100,null=True)
    status = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)
    class Meta:
        # 制定生成权限
        permissions = (
            ("show_users","查看会员管理"),
            ("insert_users","添加会员"),
            ("edit_users","修改会员"),
            ("del_users","删除会员"),
        )



# 商品分类模型
class Cates(models.Model):
    # id name pid path
    name = models.CharField(max_length=50)
    pid = models.IntegerField()
    path = models.CharField(max_length=20)
    # isdelete = models.BooleanField(default=False)
    class Meta:
        # 制定生成权限
        permissions = (
            ("show_cates","查看商品分类管理"),
            ("insert_cates","添加商品分类"),
            ("edit_cates","修改商品分类"),
            ("del_cates","删除商品分类"),
        )


# 商品模型
class Goods(models.Model):
    # 商品属性　id cateid title price store(库存) info(商品信息) pic_url status addtime clicknum ordernum
    title = models.CharField(max_length=255)
    cateid = models.ForeignKey(to='Cates')
    price = models.FloatField()
    store = models.IntegerField()
    info = models.TextField()
    pic_url = models.CharField(max_length=100)
    status = models.IntegerField(default=0)   #0　新品  1　热卖　  2　下架
    clicknum = models.IntegerField(default=0)
    ordernum = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)

    class Meta:
        # 制定生成权限
        permissions = (
            ("show_goods","查看商品管理"),
            ("insert_goods","添加商品"),
            ("edit_goods","修改商品"),
            ("del_goods","删除商品"),
        )



# 购物车模型
class Cart(models.Model):
    # uid 用户的外键
    uid = models.ForeignKey(to='Users')
    # goodsid 商品的外键
    goodsid = models.ForeignKey(to='Goods')
    num = models.IntegerField()


# 城市模型
class Citys(models.Model):
    name = models.CharField(max_length=255)
    level = models.IntegerField()
    upid = models.IntegerField()

    class Meta:
        db_table = 'citys'



# 收货地址模型
class Address(models.Model):
    uid = models.ForeignKey(to='Users')
    shouhuoren = models.CharField(max_length=50)
    shouhuophone = models.CharField(max_length=11)
    sheng = models.IntegerField()
    shi = models.IntegerField()
    xian = models.IntegerField()
    info = models.CharField(max_length=100)
    # 是否是默认收货地址
    ischecked = models.BooleanField(default=False)

# 订单模型
class Order(models.Model):
    # id uid 收货人　电话号　地址　totalprice 支付方式　快递　订单创建时间　订单支付时间　状态(０　新订单　１　支付　２　发货)
    uid = models.ForeignKey(to="Users")
    shouhuoren = models.CharField(max_length=50)
    shouhuophone = models.CharField(max_length=11)
    shouhuoaddress = models.CharField(max_length=100)
    buytype = models.CharField(max_length=10)
    wuliu = models.CharField(max_length=10)
    totalprice = models.FloatField()
    addtime = models.DateTimeField(auto_now_add=True)
    buytime = models.DateTimeField(null=True)
    # 状态(０　新订单　１　支付　２　发货)
    status = models.IntegerField(default=0)

    class Meta:
        # 制定生成权限
        permissions = (
            ("show_order","查看订单管理"),
            ("insert_order","添加订单"),
            ("edit_order","修改订单"),
            ("del_order","删除订单"),
        )

# 订单详情模型
class OrderInfo(models.Model):
    # id orderid goodsid num price pic_url title
    orderid = models.ForeignKey(to='Order')
    goodsid = models.IntegerField()
    title = models.CharField(max_length=255)
    price = models.FloatField()
    pic_url = models.CharField(max_length=100)
    num = models.IntegerField()
